import request from "@/utils/request";
import qs from 'qs'

const wxHttp = {
  get: (url, params, isToekn = true) => {
    return request({
      url: url,
      headers: {
        isToken: isToekn,
        'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8 '
      },
      method: 'get',
      params: params
    })
  },
  post: (url, params, isToekn = true) => {
    return request({
      url: url,
      headers: {
        isToken: isToekn,
        'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8 '
      },
      method: 'post',
      data: qs.stringify(params)
    })
  },
  jsonPost: (url, params) => {
    return request({
      url: url,
      method: 'post',
      data: params
    })
  },
  upload: (url, file, onProgress) => {
    const data = new FormData()
    data.append("file", file)
    return request({
      url: url,
      method: 'post',
      headers: {
        'Content-Type': 'multipart/form-data'
      },
      onUploadProgress: onProgress,
      data
    })
  }
}

export default wxHttp
